<?php
/**
 * @title 5473. 灯泡开关 IV - 前缀匹配简化
 * @author start2004
 */


class Solution {

    /**
     * @param String $target
     * @return Integer
     */
    function minFlips($target) {
        /**
         * @since 2020-07-26 长度
         */
        $len = strlen($target);

        /**
         * @since 2020-07-26 起点
         */
        $next = implode("", array_fill(0, $len, "0"));

        /**
         * @since 2020-07-27 反转次数
         */
        $deep = 0;

        /**
         * @since 2020-07-27 遍历
         */
        $s = true;
        for($i=0; $i<$len; $i++){
            if($s){
                if($next[$i] != $target[$i]){
                    $deep++;
                    $s = !$s;
                } else {}
            } else {
                if($next[$i] == $target[$i]){
                    $deep++;
                    $s = !$s;
                } else {}
            }
        }

        /**
         * @return
         */
        return $deep;
    }
}



/**
 * @url http://127.0.0.1/leetcode/202007/2020.07.26_4.php
 */
$datas = [
    // "10111",
    // "101",
    // "00000",
    // "001011101",
    // "000101000001010101110010",
    // "111100001011111100111011110011100010100",
    "110111001101111100110001110001101110111011001111110110110000101101111000111101011001011001011101011000011001011110010101011011011111011110110000000011010101101001011100110111111110011000010110010011001100000111100011100011111100111101110000001010010101110000111101100101010000011100001011000110100100001100000001111010110110001010010011110000101111101111001101011000101001010111001110110000011100000110000100000100000001000101000010111111100000101001000100001001001110101000101010111010011111110010101010110010000010101111100111010110111011011010001001101001110011100011111111100000000010001101100100101011011110000001011000000100101001110001001011100000011010001111101011111010111111000010110010001100000011000111010100011000111011000001111111011110000011011001100010001011000001101010000011011110101101001011100010001111110110010010011010111111101000101110100100011101101010011110011011101000011111100010011100000000100110110010000000001000100000111011110001000001001001001010100111010011100110001101100000010011100010100011011111010010100111101110100010101011111100111010101111101110101001111000110010111101111101110101100010100001000100010110010101011000111100100101100101010000111011110010100010000111111110010001101001110001101111000000000010000111111010100000100100010011000111010101110001001010010011111011110100000001011110110101000111010010100111101100001100001111011101110010101100011111100101110010001001000101000000101001101100010110100000001111000110011110010000100000010010001001100010100001100000000000111100011010111001001101001111011111000011000010000001011110000100010001011111101010010101110100101000111101110110111100101101111101100100000001011010101011101010110110110001110101001001110110101100011011110101000100011011110101100011011011010010001001100010011000011100011001001101110101110100111100001011101100001101110110110011010000111011101011100001101111101000000000100001100000100001011111111111111001101000001101000101000110101001001100010000000101111100100001110001011010110001101010000010101110110101100111100011000110000011000110011100000011001100100110111011010110101000110100110101100110001100101111110110101010011000000100110110101111000000010000010101110011010101011101011000110101100010010001000101011111011111001101010111101111011110101001111010001011100001010100110101000000011010011001111100001001000100011010100000000110000110000111111000101010101000000110010010001100111010000000010110101111101010101101111101010000011111100101111000100010100111101101101011000101101110111111100010101111110110111111010010111010101011101100001001100010000000010110111110010101011110111000001110000010000101011111000101001000100101110001110100111011101000100101001111100100101010101111100001011011001100110011111011111011110010111000110011011100010011011011000110100010010001001001111110011110011010001001101010101011000011000011011011111110011100110110001011100010101010000111001010111110001000001101011110011111010110111100011010000011011101001110010001100001110110011101100011001100111111001010110101101010010001011011000100101111100101100010000100011110001110110100100010101101111000000000000011101001101011000000111010000111001110001010100010011110010001000110010110001110100100110110111101101010101011101001001100111000110000100101100101111011000010010110111000000000000001101110110111101010101010010110100011000000011100010011111101110001100001100101011111101100001111010000001000001111110010100011000000010011110011101101111111111000011001101011110100101101111101111100000110001000010010100010110111000010101101101101100101001001101101100000000100010100100010111101010001101110101010000010011000011101100110011100001110101000111100000010010001111000100000001000011011110000011000001000111111011011010000011100110101101011001111010101110010111100110010000001011111100011011010110100011111011001010001000000111011111001001110111101100010000110101101001010010010111010000001010001010000001001101110010011000000100100110111101111110011111110101101000000110111001000101110110000010111100110011110011101101101000011101101100100110000100000000001110000011011000100001100100010001110000111001010101001111101101010100000010100101110101110000011010101101100100101110000010100101110000110101000001000000010010101100100010000000001101000110101110110000001001001101110011110000010110011000111110001100010111101011100000101111101010000011111101110100100110001111011111100101010110110010100000011011011000010110010011011110001000101011011101001111111110101110101001010111011101010000001111101110110101011011110011111110001011010011101110000000101100110011010000101110100101001110110001001110101011111111110110000101000101110110001011011110001100100000100011111111001010111101000111101001011110101111001111110111000100100101001001011101000000010001011000100011111100011110011001100001100010110000111111100101110110101100011101001110101100111010101101011111100001000100010011010100111100100111000110100101101011010001101001100001100001101000110000101110010011110000100001101110001111100110001101110101001000000000101111111010000011001000110110011101011010101101110100011110111110010000011111011101001100100011001110010111010111011110000101010010111110111000010000111111010111111101111111011000001101011000011111100011101110010111111011011111100100101000000010101101000111111111110010001111001010101100101100100010010101001011011110010001100011001111101010001000001010110010100100111001001101000011000111101110000101111010100010010101111101001010110000101101000111010011101111100110001100010100100100000010011100110010101000010010000111111110101111001110011111111001000011111100100010110001001010010100111001010010100001010001011100000000111010111010000000000011100010101100000001000011111000010100110001001110110110100011111000011100100110010101010110010011100000010010101111001111000110111001010111010100011101001000110101101000011111100000001100011010111011011001100100000100110000100010101000110001000111100101110011110011011000110101101000001110101101000000010000110100110000001110111110010101000010111010000000000111110101000111100111111011101100110100010100111010000011011001001110001010000101110001110010101001111110001011000010100100011000001111100000000011100111011111010010111100010101101111001100010111011101010101101010001101111011110110001010000001110111000011111111011110010011110110010011001011001100100111001001110011110111110110011111111110010011111100100101101001010100011000101111101101111110110110111000100100011010101001111011111010000110011101100000001010111010101111111110111111010100101011011110000111101100111000100100100111101100001100111000111010011111011010110001101111010000011101110111010110110111010011011011101000100010011100010110110000100001100000101100100010111111011101101110011001101000110111100010100001100101100010011011011100001011100100101010100001000011101101001111111110110101100111000101100001010011101111100001100000111101001101011100101000010010001111000011010000101011010100100101001101011101100001110011000100110001001000011111000110100010001111111001110000100010110011111011110001000010001110000000011010011111110011001101110000110101001110101010101011101010000101110110101101000010101001001110101001101110111110010010001111100100101101110000011010000111100100011001001101100011101000000111011100010110100110000100010101000001111110100011010101101111001011111111010111010011011101110010000011111100010000000011111100010111111101100100010111010000100100010100101111000000000010100111011111100111000001010000110010000111111100011001010000011010010101011000000111110110010101111101010111010101000010101010001100110000100101110010001111010000110110000001000011000111110010101001100011101101001010000111111111011100100001000010111101111100111000010001010111011000110010011111110111100110100000000100101111101101000000100110101111011010110010101001001111000101010001011110010100011100111001101110110101010111111010010011100100101011000011000101110110100100111000001111101100101111010011111010010110000111000100110001111111111110001000001111000101000101010110011100000011110011001101000011100100110110000111010010100000010010101000100000110001101101010101101111001000000001110001101001001011001001110111111101110100001101110111101100101011100001000101111010000011101000010001100001111111101111010011111011100010101111010110101110100011100000001101010100011110110111110101001001010001001000001000011101111010000011010010101111010100101001011111110010110011101100000101111000110011110100010010100110110",
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->minFlips($data);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
